﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using VideoBlog.Data.Entities;

namespace VideoBlog.Web.Models
{
    public class CategorySummaryViewModel
    {
        public Category Category {get; private set;}
        public PlaylistViewModel Popular { get; private set; }

        public CategorySummaryViewModel() { }
        public CategorySummaryViewModel(Category c) 
        { 
            VideoBlogEntities2 db = new VideoBlogEntities2();
            
            List<Video> vids = new List<Video>();
            if (c != null)
            {
                Category = db.Category.Include("Playlist").Include("Playlist.Video").Where(o => o.CategoryID == c.CategoryID).First();
                vids = db.Video.Include("Playlist").Include("Playlist.Category").Where(o => o.Playlist.Category.CategoryID == Category.CategoryID).OrderByDescending(o => o.VideoViewCount).Take(5).ToList();
            }
            else
                vids = db.Video.Include("Playlist").Include("Playlist.Category").OrderByDescending(o => o.VideoViewCount).Take(5).ToList();
            Popular = new PlaylistViewModel("Popular videos", vids,null);
        }
    }
}
